package com.example.sales_svc.service;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.example.sales_svc.model.AuctionAsset;
import com.example.sales_svc.repository.AuctionAssetRepository;

@Service
public class AuctionAssetService {

    @Autowired
    private AuctionAssetRepository repository;

    public AuctionAsset createAsset(AuctionAsset asset) {
        asset.setStatus("草稿");
        asset.setCreatedTime(LocalDateTime.now());
        return repository.save(asset);
    }

    public AuctionAsset updateStatus(Long id, String status) {
        AuctionAsset asset = repository.findById(id).orElseThrow();
        asset.setStatus(status);
        return repository.save(asset);
    }

    public List<AuctionAsset> findAll() {
        return repository.findAll();
    }

    public void delete(Long id) {
        repository.deleteById(id);
    }

}
